package com.core.zyyz.amc.modules.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.core.zyyz.constants.FunctionCode;
import com.core.zyyz.pcmc.domain.ValueSetValue;
import com.core.zyyz.pcmc.service.ValueSetValueService;
import com.core.zyyz.util.CodeMakerUtil;
import com.core.zyyz.util.PublicUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.core.common.annotation.Log;
import com.core.common.core.controller.BaseController;
import com.core.common.core.domain.AjaxResult;
import com.core.common.enums.BusinessType;
import com.core.zyyz.amc.modules.domain.AmcCusPartnerInfoB;
import com.core.zyyz.amc.modules.service.AmcCusPartnerInfoBService;
import com.core.common.utils.poi.ExcelUtil;
import com.core.common.core.page.TableDataInfo;

/**
 * 中介机构Controller
 *
 * @author lfs
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/amc/agency")
public class AmcCusPartnerInfoBController extends BaseController
{
    @Autowired
    private AmcCusPartnerInfoBService amcCusPartnerInfoBService;
    @Autowired
    private ValueSetValueService valueSetValueService;

    /**
     * 查询中介机构列表
     */
    @PreAuthorize("@ss.hasPermi('amc:agency:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmcCusPartnerInfoB amcCusPartnerInfoB) {
        startPage();
        List<AmcCusPartnerInfoB> list = amcCusPartnerInfoBService.selectAmcCusPartnerInfoBList(amcCusPartnerInfoB);
        return getDataTable(list);
    }

    /**
     * 获取中介机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('amc:agency:query')")
    @GetMapping(value = "/{partnerId}")
    public AjaxResult getInfo(@PathVariable("partnerId") String partnerId) {
        return success(amcCusPartnerInfoBService.selectAmcCusPartnerInfoBByPartnerId(partnerId));
    }

    /**
     * 根据页面的集值定义去查询具体的集值数据（页面中下拉框的值）
     *
     * @return
     */
    @GetMapping("/valueSetCodeList")
    public AjaxResult valueSetCodeList(){
        Map<String, Object> map = new HashMap<String, Object>();
        //partner_type 中介机构类型;gdfamc_lib_outorin 库内库外;aptitude 资质(证券/非证券) （会计师事务所填写;range 资产专项评估资质（土地、房地产）
        String[] str ={"partner_type", "gdfamc_lib_outorin", "aptitude","range"};
        ValueSetValue value = new ValueSetValue();
        for(int i=0;i<str.length;i++){
            value.setValueSetCode(str[i]);
            List<ValueSetValue> valueSetValues = valueSetValueService.selectValueSetValueList(value);
            map.put(str[i], valueSetValues);
        }
        return success(map);
    }

    /**
     * 新增中介机构
     */
    @PreAuthorize("@ss.hasPermi('amc:agency:add')")
    @Log(title = "中介机构", businessType = BusinessType.INSERT)
    @PostMapping("/insertAgency")
    public AjaxResult add(@RequestBody AmcCusPartnerInfoB amcCusPartnerInfoB) {
        return toAjax(amcCusPartnerInfoBService.insertAmcCusPartnerInfoB(amcCusPartnerInfoB));
    }

    /**
     * 修改中介机构
     */
    @PreAuthorize("@ss.hasPermi('amc:agency:edit')")
    @Log(title = "中介机构", businessType = BusinessType.UPDATE)
    @PostMapping("/updateAgency")
    public AjaxResult edit(@RequestBody AmcCusPartnerInfoB amcCusPartnerInfoB)
    {
        return toAjax(amcCusPartnerInfoBService.updateAmcCusPartnerInfoB(amcCusPartnerInfoB));
    }

    /**
     * 删除中介机构
     */
    @PreAuthorize("@ss.hasPermi('amc:agency:remove')")
    @Log(title = "中介机构", businessType = BusinessType.DELETE)
    @DeleteMapping("/{partnerIds}")
    public AjaxResult remove(@PathVariable String[] partnerIds)
    {
        return toAjax(amcCusPartnerInfoBService.deleteAmcCusPartnerInfoBByPartnerIds(partnerIds));
    }
}
